<div class="container-fluid">
    <div class="wrapper">
        <div class="panel" id="nav">
            <div class="panel-heading"><h3 class="panel-title">shipmentId返仓申请</h3></div>
            <div class="panel-body">
                <form action="__URL__/shipmentIdBack" method="get" onsubmit="return checkSave()">
                    <div class="container-fluid">
                        <div class="col-sm-12 col-md-3  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">shipmentid</span>
                                <input class="form-control" type="text" name="shipmentid" value="">
                            </div>
                        </div>
                        <div class="col-md-2 add-space">
                            <input class="btn btn-primary" type="submit" value="查询">
                        </div>
                    </div>
                </form>
                <div class="clearfix"></div>
                <div style="color: red;margin-left: 10px;">
                    <b>
                        Shipmentid返仓申请使用条件:<br>
                        1.返仓申请时要确定亚马逊平台上的数据跟公司系统的一致，单个返仓亚马逊平台上就要把对应SKU数量改为零，全部返仓的话就要在亚马逊平台上取消对应的计划单<br>
                        2.Shipmentid状态为仓库拣货确认后，待物流计划前；<br>
                        3.由于账号受限了某个Shipmentid全部不要了可以申请返仓；<br>
                        4.某个Shipmentid下的某个SKU由于下架侵权不要了，某个SKU不要了(注意：非修改数量，是不要了，可以对某个SKU返仓申请)；
                    </b>
                </div>
                <div class="clearfix"></div>
                <hr>
                <form action="__URL__/backShipmentIdSave" method="post" onsubmit="return checkFrom()">
                    <table class="table table-striped  table-hover" cellspacing="0" width="100%">
                        <thead>
                        <tr>
                            <th width="20"><input id="checkAll" type="checkbox"></th>
                            <th>序号</th>
                            <th>编号</th>
                            <th>账号</th>
                            <th>站点</th>
                            <th>SKU</th>
                            <th width="200">产品名称</th>
                            <th>数量</th>
                            <th>是否退税</th>
                            <th>公司主体</th>
                            <th>销售员</th>
                            <th>返仓类型</th>
                            <th>备注</th>
                        </tr>
                        </thead>

                        <tbody>
                        <volist name="data" id="da" >
                            <volist name="da.detail" id="dt" key="num">
                                <tr>
                                    <td class="text-center"><input name="planDetailId[]" type="checkbox" value="{$dt.id}"></td>
                                    <td>
                                        <input name="detailId[]" type="hidden" value="{$dt.id}">
                                        <input name="planId" type="hidden" value="{$da.id}">{$num}
                                        <input name="deliveryorders_id[]" type="hidden" value="{$dt.deliveryorders_id}">
                                    </td>
                                    <td><input type="hidden" value="{$da.shipmentid}" name="shipmentid[]">{$da.shipmentid}</td>
                                    <td><input type="hidden" value="{$da.account_id}" name="account_id[]">{$da.account_name}</td>
                                    <td><input type="hidden" value="{$da.site_id}" name="site_id[]">{$da.site_id}</td>
                                    <td><input type="hidden" value="{$dt.sku}" name="sku[]">{$dt.sku}</td>
                                    <td><input type="hidden" value="{$dt.sku_name}" name="sku_name[]">{$dt.sku_name}</td>
                                    <td><input type="hidden" value="{$dt.quantity}" name="quantity[]">{$dt.quantity}</td>
                                    <td><input type="hidden" value="{$dt.export_tax_rebate}" name="export_tax_rebate[]">{$dt.export_tax_rebate}</td>
                                    <td><input type="hidden" value="{$dt.enterprise_dominant}" name="enterprise_dominant[]">{$dt.enterprise_dominant}</td>
                                    <td><input type="hidden" value="{$da.seller_id}" name="seller_id[]">{$da.seller_name}</td>
                                    <td class="backType">
                                        <select type="text" name="back_type[]" class="w120" value="">
                                            <option value="0">请选择</option>
                                            <volist name="back_type" id="ba">
                                                <option value="{$key}">{$ba}</option>
                                            </volist>
                                        </select>
                                    </td>
                                    <td><input type="text" name="reason[]" value="" class="w120" placeholder="备注"></td>
                                </tr>
                            </volist>
                        </volist>
                        </tbody>
                    </table>
                    <div class="clearfix clear"></div>
                    <div class="col-md-offset-5 col-md-2 add-space">
                        <input class="btn btn-primary" type="submit" value="返仓申请">
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<!--<script type="text/javascript" src="__PUBLIC__/javascripts/admin/layer/layer.js"></script>-->
<!-------------------------当前页面js引用处--------------------------------->
<script>
    $(function () {
        $("input[name='shipmentid']").val("<?php  echo $_GET['shipmentid'];?>");
        $("#checkAll").click(
            function() {
                if (this.checked) {
                    $("input[name='planDetailId[]']").prop('checked', true);
                } else {
                    $("input[name='planDetailId[]']").prop('checked', false);
                }
            }
        );
    });
    function checkSave() {
        if($("input[name='shipmentid']").val()==''){
            layer.msg('请输入shipmentid', {icon: 5});
            return false;
        }else{
            return true;
        }
    }
    function checkFrom() {
        var id = [];
        var err = 1;
        var status = '<?php echo $status ?>';
        $('input[name="planDetailId[]"]:checked').each(function(){
            var aa = $(this).parent('td').siblings('.backType').find('select').val();
            if($.trim(aa) == 0){
                err = 3;
            }
            id.push($(this).val());
        });
        if(id==''){
            layer.msg('请选择要返仓的数据', {icon: 5});
            return false;
        }
        if(err==3){
            layer.msg('请选择要返仓的类型', {icon: 5});
            return false;
        }
        if(status >20 && status<50){
            layer.msg('此票货已录入装箱数据，请联系仓库人员删除装箱数据再操作', {icon: 5});
            return false;
        }else if (status==50){
            layer.msg('此票货是待发货状态，请联系物流人员删除物流计划单再操作', {icon: 5});
            return false;
        }else{
            if(confirm('你确定要返仓吗？')==true) {
                return true;
//            $.ajax({
//                url: "__URL__/backShipmentIdSave",
//                type: 'post',
//                async: true, //default: true
//                data: {'id':id},
//                dataType: 'json', // default: Intelligent Guess (xml, json, script, or html)
//                success: function (data, textStatus, jqXHR) {
//                    //alert(data)
//                    if (data == true) {
//                        layer.msg('成功', {icon: 6});
//                        window.location.href='__URL__/shipmentIdBack';
//                    } else {
//                        layer.msg('失败', {icon: 5});
//                    }
//                }
//            });
            }
        }

        return false;

    }
</script>